using Pvp.Ecs;

namespace Pvp
{
    /// <summary>
    /// 通过攻击时伤害判定来破坏路障
    /// </summary>
    [EntityDeclare((int)EntityType.gear, (int) GearType.可破坏路障1)]
    class EntityDeclare1643 :BaseEntityDeclare
    {
        private ILifeUnit m_LifeUnit;
        public override void OnEntityCreate(Entity entity,object userData)
        {
            entity.AddComponent<IUnit>();
            entity.AddComponent<IView>();
            entity.AddComponent<IHurtBox>();
            entity.AddComponent<ILifeUnit>();
            var gear =  entity.AddComponent<IGearUnit>();
            gear.GearDestroyTrigger = OnDestroy;
        }

        private bool OnDestroy(IGearUnit gear)
        {
            if (m_LifeUnit != null)
            {
                return m_LifeUnit.LifeValue <= 0;
            }

            gear.TryGetCombineComponent<ILifeUnit>(out m_LifeUnit);
            if (m_LifeUnit == null)
                return false;
            return m_LifeUnit.LifeValue <= 0;
        }
    }
}